package com.test.message.builder;

import com.test.message.AbstractMessage;
import com.test.message.MessageType;
import com.test.message.wrapper.Payload;
import com.test.utils.SerializationUtil;

public class MessageBuiler {
	
	public static byte[] build(AbstractMessage message){
		int type = MessageType.getType(message.getClass());
		Payload payload = new Payload();
		payload.setType(type);
		payload.setMessage(SerializationUtil.serialize(message));
		return SerializationUtil.serialize(payload);
	}
	
	public static Payload getPayload(byte[] payload) {
		return SerializationUtil.deserialize(payload, Payload.class);
	}
	
}
